﻿<?php
/**
 * Akimimi front
 * StarView
 * by M.Wang
 */

require_once "../". $GLOBALS["local"] ."/"."product.php";
require_once "../app/views/BaseView.php";

require_once '../app/constants/Order.php';
/**
 * star vote management
 */
class StarView extends BaseView{
    protected $boxClass = 'starBox';
    protected $staticClass = 'starSelected';
    protected function getColor( $bool_yellow = true ){
        return $bool_yellow ? 'Y' : 'G';
    }
    /**
     * Use for display point
     * 
     * @param float $float_int
     * @param boolean $bool_yellow
     * @return string
     */
    public function getStatic( $float_int, $bool_yellow = true ){
        if( $float_int < 1 )
            $str_html = "";
//            $str_html = "<div style='margin-top:15px;margin-left:20px;'>" . PRODUCTAVGPOINTISEMPTYTXT . "</div>";
        else
	        $str_html = "<div style='float:left;margin-top:10px;margin-right:20px;margin-left: 30px;font-size:13px;'>" . PRODUCTPOINTAVGTXT 
	                  . "<span style='color:red;font-size:15px;'>" . $float_int . "</span></div>"
	                  . "<div style='margin-top:10px;top:-10px;' class='{$this->boxClass}" 
	                  . $this->getColor( !$bool_yellow ) 
	                  . "'><div class='{$this->staticClass}" 
	                  . $this->getColor( $bool_yellow ) 
	                  . "' style='width:" 
	                  . (round($float_int)*30) 
	                  . "px;'></div>"
	                  . "</div>" 
	                  ;
        return $str_html;
    }
    /**
     * Use for vote
     * 
     * @param int $int_productid
     * @param boolean $bool_yellow
     * @return string
     */
    public function getLive( $int_productid, $bool_yellow = true ){
        $str_html = "<div style='margin-left:25px;' class='{$this->boxClass}" 
                  . $this->getColor( $bool_yellow ) 
                  . "'><div id='starPointBox' class='{$this->staticClass}"
                  . $this->getColor( !$bool_yellow ) . "'>";
        //$str_js = "javascript:submitVoteStar('#starBox',{$int_productid},%s);";
        $str_js = "javascript:$('#starPointBox').get()[0].style.width=%s*30+'px';$('#starPointValue').val(%s);$('#voteComments').get()[0].focus();void(0);";
        $str_a = "<a class='star%s' href=\"{$str_js}\" title='%s'></a>";
        for( $int_i = 1; $int_i <= 5; $int_i ++ )
           $str_html.= sprintf( $str_a, $int_i, $int_i, $int_i, $int_i ); 
		$str_html.="</div></div>";
		//first on focus in $('#starPointBox').focus(); in ProductView.php
		return $str_html;
    }
    
    /**
     * Get comments box
     * 
     * @return string
     */
    public function getCommentBox(){
        $str_html = "<div style='margin-left:20px;'>";
        $str_html.= "<div style='float:left;font-size:13px;'>" . DEALEVALUATE . "</div>";
        $str_html.= "<div style='float:left;margin-left:10px;*margin-left:0px;_margin-left:0px;'><textarea id='voteComments' name='content' cols='85' rows='5' ></textarea></div>";
        $str_html.= "<div class='clear'></div>";
        $str_html.= "</div>";
        $str_html.= "<div style='margin-left:100px;margin-top:10px;margin-bottom:20px;'>
			        <input type='button' value='发表评论' class='qbutton' onclick='voteService.submitMyComments();' />
			        &nbsp;&nbsp;<span style='color:red;'>   只有购买该商品的用户，才能发表评论   </span>
			        </div>";
        /**
         * @todo set ajax submit action
         */
        return $str_html;
    }
    
    /**
     * Get full view
     * product page show top first
     * @param float $float_avgPoint
     * @param int $int_productid
     * @return string
     */
    public function getFirstStarBox( $float_avgPoint, $int_productid, $arr_comments = null, $opinionAllNum, $orderInfo ){
        $str_html = $this->getComments( $arr_comments, $orderInfo );
        $str_html.= "<div id='submitComment' style='padding-left:30px; border-top:1px solid #DEDEDE;'><form id='starBoxForm' action='/a/savestarchoice' onsubmit='return false;'>"
                  //. $this->getStatic($float_avgPoint)
                  . "<div style='margin-top:20px;margin-bottom:10px;'>"
                  . "<div style='float:left;margin-left:20px;_margin-left:10px;margin-top:10px;font-size:13px;margin-right:20px;*margin-right:25px;_margin-right:20px;'>" . USERGRADE . "</div>"
                  . $this->getLive($int_productid, false)
                  . "<div class='clear'></div>"
                  . "</div>"
                  . $this->getCommentBox()
                    . "<input type='hidden' id='starPointValue' name='starpoint' value='0' />"
                    . "<input type='hidden' id='voteProductId' name='product_id' value='{$int_productid}' />"
                  . "</form></div>";
        
        return $str_html;
    }
    
    /**
     * Get full view
     * 
     * @param float $float_avgPoint
     * @param int $int_productid
     * @return string
     */
    public function getStarBox( $float_avgPoint, $int_productid, $arr_comments = null, $opinionAllNum ){
    	//1013 add begin
        $opinionAllNum=$opinionAllNum[0]["opinionNumber"];
    	$pager = new Pager();
    	$itemsPerPage = $GLOBALS["config"]['items_per_page'];
        $pager->setJavascriptFunction("javascript:ProductContent.ajaxOpinionPaginate");
        $headerPaginate = $pager->paginate(1, $opinionAllNum, "", $itemsPerPage);
        
    	//1013 add end
        $str_html = $this->getComments( $arr_comments );
        
        $str_html.="<div class='p2_page' id='opinionPagination'>{$headerPaginate}</div>";

        $str_html.= "<div id='submitComment' style='padding-left:30px; margin-top:1px solid #DEDEDE;>"
                  . "<form id='starBoxForm' action='/a/savestarchoice' onsubmit='return false;'>"
                  //. $this->getStatic($float_avgPoint)
                  . "<div style='margin-top:20px;margin-bottom:10px;'>"
                  . "<div style='float:left;margin-left:20px;_margin-left:10px;margin-top:10px;font-size:13px;margin-right:20px;*margin-right:25px;_margin-right:20px;'>" . USERGRADE . "</div>"
                  . $this->getLive($int_productid, false)
                  . "<div class='clear'></div>"
                  . "</div>"
                  . $this->getCommentBox()
                    . "<input type='hidden' id='starPointValue' name='starpoint' value='0' />"
                    . "<input type='hidden' id='voteProductId' name='product_id' value='{$int_productid}' />"
                  . "</form></div>";
        return $str_html;
    }
    
    public function getComments( $arr_comments, $orderInfo ){
    	//显示订单相关信息
    	$quantity = $orderInfo[0]["quantity"];
    	$orderTime = $orderInfo[0]["created"];
    	$shippingKey = $orderInfo[0]["shipping_expect"];
    	$shippingTitle = Order::getShippingMethod($shippingKey);
    	$paymentKey = $orderInfo[0]["payment_method"];
    	$paymentTitle = Order::getPaymentMethod($paymentKey);
    	
        $str_result = "<div id='commentsViewBlock'>";
        if( !empty( $arr_comments ) ){
	        foreach ($arr_comments as $arr_comment){
                //add image and user name
                $userRank = self::getUserRank($arr_comment['userrank']);
	        	$str_new_add = "<div class='pj_left'>";
	        	$str_new_add .= "    <div class='pj_user_img'>";
	        	$str_new_add .= "        <img style='width:156px;height:156px;' alt='' src='".ConfigConstants::getTLayoutPath()."/image/rankpic/{$arr_comment['userrank']}.jpg' />";
	        	$str_new_add .= "    </div>";
	        	$str_new_add .= "    <p>用户名：<span>{$arr_comment['username']}</span></p>";
	        	$str_new_add .= "    <p>会员等级：<span>{$userRank}</span></p>";
	        	$str_new_add .= "</div>";
	        	//end
	            $str_result.= "<div class='comment_div' style='margin-top:10px;'>
	                               {$str_new_add}
	                               <div style='float:right;width:760px;'>
	                                   <div class='pj_body_bt'>
	                                       <ul>
	                                           <li class='title_1'>用户类型：</li><li class='title_2'>{$userRank}</li>";
	           if(!empty($quantity))
	               $str_result.= "<li class='title_1'>购买数量：</li><li class='title_2'>{$quantity}</li>";
	           if(!empty($paymentTitle))
		           $str_result.= "<li class='title_1'>支付方式：</li><li class='title_2'>{$paymentTitle}</li>";
               if(!empty($shippingTitle))
		           $str_result.= "<li class='title_1'>快递方式：</li><li class='title_2'>{$shippingTitle}</li>";
               if(!empty($orderTime))
		           $str_result.= "<li class='title_1'>购买时间：</li><li class='title_2'>{$orderTime}</li>";
	           $str_result.= "             </ul>
	                                   </div>
		                               <div class='pj_pl_hf' style='width:730px;color:#000000;border-bottom:1px dotted #CCCCCC;margin-left:10px;margin-top:0px;margin-bottom:0px;'>
		                                   <p>".USERCOMMENTINFO."</p>{$arr_comment['content']}"
			                              ."&nbsp; &nbsp; &nbsp; &nbsp; <span>"
			                              .PUBLISHTIME."{$arr_comment['created']}</span>
			                           </div>";
	            if( !empty( $arr_comment['reply_content'] ) ){
	                $str_result.= "<div class='pj_pinglun' style='width:720px;color:#000000;margin:7px 5px 0 15px;'>
	                                   <p>".MIMIREPLY."</p>{$arr_comment['reply_content']} &nbsp; &nbsp; &nbsp; &nbsp;
	                                   <span>".MIMIREPLYTIME."{$arr_comment['reply_created']}</span>
                                   </div>";
	            }
	            $str_result.= "    </div>";
                $str_result.= "<div class='clear'></div>";
	            $str_result.= "</div>";
	            
//	            else{
//	                $str_result.= "<div class='pj_pl_hf'>" . RECOMMENTSISEMPTYTXT . "</div>";
//	            }
	        }
        }
        return $str_result.'</div>';
    }
    
    public function getUserHeader( $arr_comments ){
        $str_html = "<div style='text-align:center;>"
                  . $arr_comments['user_name'] . '<br />'
                  . $arr_comments['user_rank']
                  . "</div>";
        return $str_html;
    }
    
    public function getOrderInfo( $arr_comments ){
        $str_html = "<div>"
                  . $arr_comments['user_certf']
                  . $arr_comments['order_payment_method']
                  . $arr_comments['order_shipping_expect']
                  . $arr_comments['order_created']
                  . $arr_comments['ordre_delivery_address_1']
                  . "<div class='clear'></div></div>";
        return $str_html;
    }
    
    public function getCommentsList( $arr_comments, $int_page, $int_limit ){
        $str_html = ""
                  . $this->getComments( $arr_comments )
                  . "</div><div style='text-align:center;'>"
                  . "</div>";
        return $str_html;
    }
    
    /**
     * Get Thanks Message
     * 
     * @return string
     */
    public function getThanksMessage(){
        return PRODUCTVOTEDFINISHTXT;
    }
    
    /**
     * Get user rank
     * 
     * @return string
     */
    public function getUserRank($rank){
    	if($rank == 1){
    		return CUSTOMERRANK1;
    	}elseif($rank == 2){
    		return CUSTOMERRANK2;
    	}elseif($rank == 3){
    		return CUSTOMERRANK3;
    	}elseif($rank == 4){
            return CUSTOMERRANK4;
        }elseif($rank == 5){
            return CUSTOMERRANK5;
        }elseif($rank == 6){
            return CUSTOMERRANK6;
        }else{
        	return "";
        }
    } 
    
}
?>
